﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using JobbJakt;

namespace JobbJaktWeb
{
    public partial class SignUp : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
         
        }

        protected void ButtonSignUpRegistration_Click(object sender, EventArgs e)
        {
            try
            {
                string userName = TextBoxSignUpUserName.Text.Trim();
                string passWord = TextBoxSignUpPassWord.Text.Trim();

                if (Users.PrintUser(userName) == null)
                {
                    Users newUser = new Users()
                    {
                        UserName = TextBoxSignUpUserName.Text.Trim(),
                        SocialSecurityNumber = " ",
                        Password = TextBoxSignUpPassWord.Text.Trim(),
                        Authorization = 0,
                        FirstName = " ",
                        LastName = " ",
                        Address = " ",
                        ZipCode = " ",
                        City = " ",
                        Phone = " ",
                        Email = " ",
                        Interest = " ",
                        Attributes = " ",
                        Photo = " ",
                        RegistrationDate = DateTime.Today,
                        Active = true,
                        DriversLicense = false
                    };
                    Users.AddUser(newUser);
                    Session["Authorization"] = newUser.Authorization;
                    Session["UserName"] = newUser.UserName;
                    Response.Redirect("Home.aspx", false);
                }
                else
                {
                    LabelAlreadyExists.Visible = true;
                }
            }
            catch (Exception ex)
            {
                ErrorTable newErrorTable = new ErrorTable(){Message = ex.Message, Type = ex.GetType().ToString()};
                ErrorTable.InsertError(newErrorTable);
                throw new Exception();
            }
        }
    }
}